package day01;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class yieldTest {
    public static void main(String[] args) {
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                int count = 0;
                for (; ; ) {
                    log.debug("count: {}", count++);
                }
            }
        };

        Runnable r2 = new Runnable() {
            @Override
            public void run() {
                int count = 0;
                for ( ; ; ) {
                    // 让出时间片
//                    Thread.yield();
                    log.debug("            count: {}", count++);
                }
            }
        };

        // 创建两个线程
        Thread t1 = new Thread(r1,"t1");
        Thread t2 = new Thread(r2,"t2");
        t1.setPriority(10);
        t2.setPriority(1);
        t1.start();
        t2.start();
    }
}
